//事件封装
function addEvent(el, type, fn) {
    if (el.addeventListener) {
        el.addeventListener(type, fn, false)
    } else if (el.attachEvent) {
        el.attachEvent('on' + type, function() {
            handle.call(el);
        })
    } else {
        el['on' + type] = fn;
    }
}
// 解除事件
function removeEvent(elem, type, fn) {
    if (elem.addeventListener) {
        elem.removeEvent(type, fn, false)
    } else if (elem.attachEvent) {
        elem.detachEvent('on' + type, fn)
    } else {
        elem['on' + type] = null;
    }
}
// 阻止默认事件
function preventDefaultEvent(e) {
    var e = e || window.event;
    if (e.preventDefault) {
        event.preventDefault();
    } else {
        event.returnValue = false
    }
}
// 阻止冒泡
function vancelBubble(e) {
    var e = e || window.event;
    if (e.stopPropagation) {
        e.stopPropagation()
    } else {
        e.cancelBubble = true;
    }
}
// 滚动条距离兼容
function getScrollOffset() {
    if (window.pageXOffset) {
        return {
            left: window.pageXOffset,
            top: window.pageYOffset
        }
    } else {
        return {
            left: document.body.scrollLeft + document.documentElement.scrollLeft,
            top: document.body.scrollTop + document.documentElement.scrollTop
        }
    }
}

// 获取窗口高度
function getViewPortSize() {
    if (window.innerWidth) {
        return {
            width: window.innerWidth,
            height: window.innerHeight
        }
    } else {
        // 如果浏览器是怪异模式
        if (document.compatMode === 'BackCompat') {
            return {
                width: document.body.clientWidth,
                height: document.body.clientHeight
            }
        } else {
            return {
                width: document.documentElement.clientWidth,
                height: document.documentElement.clientHeight
            }
        }
    }
}
// 文档高度
function getScrollSize() {
    if (document.body.scrollHeight) {
        return {
            width: document.body.scrollWidth,
            height: document.body.scrollHeight
        }
    } else {
        return {
            width: document.documentElement.scrollWidth,
            height: document.documentElement.scrollHeight
        }
    }
}
//找子元素
function elemChildren(node) {
    var temp = {
            'length': 0,
            'splice': Array.prototype.splice
        },
        len = node.childNodes.length;
    for (var i = 0; i < len; i++) {
        var childItem = node.childNodes[i];
        if (childItem.nodeType === 1) {
            temp[temp.length] = childItem;
            temp['length']++;
        }
    }
    return temp;
}
// 寻找父元素
function elemParent(node, n) {
    var type = typeof(n);
    if (type === 'undefined') {
        return node.parentNode;
    } else if (n <= 0 || type !== 'number') {
        return undefined;
    }
    while (n) {
        node = node.parentNode;
        n--;
    }
    return node;
}
// 获取样式属性
function getStyle(elem, prop) {
    if (window.getComputedStyle) {
        if (prop) {
            return parseInt(window.getComputedStyle(elem, null)[prop])
        } else {
            return window.getComputedStyle(elem, null);
        }
    } else {
        if (prop) {
            return parseInt(elem.currentStyle[prop]);
        } else {
            return elem.currentStyle;
        }
    }
}
// 鼠标相对于文档的坐标
function pagePos(e) {
    var sLeft = getScrollOffset().left,
        sTop = getScrollOffset().top,
        cLeft = document.documentElement.clientLeft || 0,
        cTop = document.documentElement.clientTop || 0;
    return {
        x: e.clientX + sLeft - cLeft,
        y: e.clientY + sTop - cTop
    }
}